package com.lrkj.waitress.controller;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.waitress.domain.JoinRegister;
import com.lrkj.waitress.service.IJoinRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 入伙登记Controller
 *
 * @author yajun_ren
 * @date 2022-03-17
 */
@RestController
@RequestMapping("/waitress/joinRegister")
@Api(tags = "入伙登记")
public class JoinRegisterController extends BaseController
{
    @Autowired
    private IJoinRegisterService joinRegisterService;

    /**
     * 查询入伙登记列表
     */
    @ApiOperation(value = "查询入伙登记列表", notes = "查询入伙登记列表")
    @PreAuthorize("@ss.hasPermi('waitress:joinRegister:list')")
    @GetMapping("/list")
    public TableDataInfo list(JoinRegister joinRegister)
    {
        startPage();
        this.changeParameter(joinRegister.getParams());
        List<JoinRegister> list = joinRegisterService.selectJoinRegisterList(joinRegister);
        return getDataTable(list);
    }

    /**
     * 导出入伙登记列表
     */
	@ApiOperation(value = "导出入伙登记列表", notes = "导出入伙登记列表")
    @PreAuthorize("@ss.hasPermi('waitress:joinRegister:export')")
    @Log(title = "入伙登记", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(JoinRegister joinRegister)
    {
        List<JoinRegister> list = joinRegisterService.selectJoinRegisterList(joinRegister);
        ExcelUtil<JoinRegister> util = new ExcelUtil<JoinRegister>(JoinRegister.class);
        return util.exportExcel(list, "入伙登记数据");
    }


    /**
     * 获取入伙登记详细信息
     */
	@ApiOperation(value = "获取入伙登记详细信息", notes = "获取入伙登记详细信息")
    @PreAuthorize("@ss.hasPermi('waitress:joinRegister:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(joinRegisterService.selectJoinRegisterById(id));
    }


    /**
     * 根据房间id和业主id获取入伙单
     * @param joinRegister
     * @return
     */
    @GetMapping("/selectJoinByRoomId")
    public AjaxResult selectJoinByRoomId(JoinRegister joinRegister){
	    return  AjaxResult.success(joinRegisterService.selectJoinByRoomId(joinRegister));
    }


    /**
     * 新增入伙登记
     */
    @ApiOperation(value = "新增入伙登记", notes = "新增入伙登记")
    @PreAuthorize("@ss.hasPermi('waitress:joinRegister:add')")
    @Log(title = "入伙登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JoinRegister joinRegister)
    {
        return toAjax(joinRegisterService.insertJoinRegister(joinRegister));
    }

    /**
     * 修改入伙登记
     */
    @ApiOperation(value = "修改入伙登记", notes = "修改入伙登记")
    @PreAuthorize("@ss.hasPermi('waitress:joinRegister:edit')")
    @Log(title = "入伙登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JoinRegister joinRegister)
    {
        return toAjax(joinRegisterService.updateJoinRegister(joinRegister));
    }

    /**
     * 删除入伙登记
     */
    @ApiOperation(value = "删除入伙登记", notes = "删除入伙登记")
    @PreAuthorize("@ss.hasPermi('waitress:joinRegister:remove')")
    @Log(title = "入伙登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(joinRegisterService.deleteJoinRegisterByIds(ids));
    }



    /**
     * 入伙登记审核确认
     */
    @ApiOperation(value = "入伙登记审核确认", notes = "入伙登记审核确认")
    @PreAuthorize("@ss.hasPermi('waitress:joinRegister:auditing')")
    @GetMapping(value = "/auditing/{id}")
    public AjaxResult auditing(@PathVariable("id") String id)
    {
        return AjaxResult.success(joinRegisterService.auditing(id));
    }


    /**
     * 迁出
     * @param joinRegister
     * @return
     */
    @PreAuthorize("@ss.hasPermi('waitress:joinRegister:emigrationAud')")
    @PostMapping("/emigrationAud")
    public AjaxResult emigrationAud(@RequestBody JoinRegister joinRegister){
        return toAjax(joinRegisterService.emigrationAud(joinRegister));
    }

}
